package com.weiyi.servlet04;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 
 * @description RequestDispatcher请求分发示例
 * @author 惟一
 * @date 2020年6月26日下午6:33:35
 */
@WebServlet("/some.view")
public class Some extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=UTF-8");
		PrintWriter out = resp.getWriter();
		out.println("Some do one...");
		RequestDispatcher requestDispatcher = req.getRequestDispatcher("other.view");
	//	requestDispatcher.forward(req, resp);//forward方法是把请求的内容转发到另外的一个servlet/jsp.
		requestDispatcher.include(req, resp);//include是把另一个servlet/jsp处理过后的内容拿过来与此时servlet的内容一同输出.
		out.println("Some do two...");
		out.close();
	}
}
